package sz.szsmk.citizencard.ui.adapter;

import android.content.Context;
import androidx.recyclerview.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.ViewGroup;
import android.widget.TextView;

import sz.szsmk.citizencard.R;
import sz.szsmk.citizencard.databinding.CardViewFunBinding;

import java.util.ArrayList;

/**
 * Copyright (c)2018
 * author: zdh
 * created on: 2018/8/15 16:37
 * description:
 */
public class CardViewFunAdapter extends RecyclerView.Adapter<CardViewFunAdapter.CardViewHolder> {

    private Context mContext;
    private ArrayList<String> mOpenList;

    public CardViewFunAdapter(Context homeRoutineCardActivity, ArrayList<String> openList) {
        mContext = homeRoutineCardActivity;
        mOpenList = openList;
    }

    @Override
    public int getItemViewType(int position) {
        return R.layout.card_view_fun;
    }

    @Override
    public CardViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        return CardViewHolder.creat(parent);
    }

    @Override
    public void onBindViewHolder(CardViewHolder holder, int position) {
        loadItemData(position, holder.binding);
    }

    private void loadItemData(int position, CardViewFunBinding binding) {
        TextView tv = (TextView) binding.getRoot().findViewById(R.id.card_view_tv);
        if (mOpenList != null) {
            tv.setText(mOpenList.get(position));
        }
    }

    @Override
    public int getItemCount() {
        return null == mOpenList ? 0 : mOpenList.size();
    }

    public static class CardViewHolder extends RecyclerView.ViewHolder {


        private CardViewFunBinding binding;

        public static CardViewHolder creat(ViewGroup parent) {
            CardViewFunBinding binding = CardViewFunBinding.inflate(LayoutInflater.from(parent.getContext()), parent, false);
            return new CardViewHolder(binding);
        }

        public CardViewHolder(CardViewFunBinding binding) {
            super(binding.getRoot());
            this.binding = binding;
        }


    }

}
